import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import '../../utils/toast.dart';
import '../../utils/token.dart';

class SettingPage extends StatefulWidget {
  const SettingPage({super.key});

  @override
  State<SettingPage> createState() => _SettingState();
}

class _SettingState extends State<SettingPage> {
  @override
  Widget build(BuildContext context) {
    //退出登录
    void logout() {
      TokenManager().removeToken();
      Navigator.pushNamedAndRemoveUntil(context, '/login', (route) => false);
      ToastUtil.showSuccess('退出登录成功！');
    }

    /// showDialog
    showDialogFunction(context) {
      showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: const Text("提示"),
            content: const Text("确定删除吗？"),
            actions: [
              TextButton(
                onPressed: () {
                  Navigator.of(context).pop();
                },
                child: const Text("取消"),
              ),
              TextButton(
                  onPressed: () {
                    logout();
                  },
                  child: const Text("确定")),
            ],
          );
        },
      );
    }

    return Scaffold(
        resizeToAvoidBottomInset: false,
        backgroundColor: const Color.fromARGB(255, 244, 243, 243),
        appBar: AppBar(
          title: const Text(
            '系统设置',
            style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
          ),
          backgroundColor: Colors.transparent,
          centerTitle: true,
        ),
        body: Column(children: [
          Container(
              margin: const EdgeInsets.all(20),
              padding: const EdgeInsets.all(20),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(10),
              ),
              child: Column(
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '换绑手机',
                        style: TextStyle(color: Colors.black, fontSize: 15),
                        textAlign: TextAlign.center,
                      ),
                      SvgPicture.asset(
                        'assets/mine/ic_btn_more.svg',
                        color: Colors.red,
                        width: 20,
                        height: 20,
                      ),
                    ],
                  ),
                  const SizedBox(height: 30),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '修改密码',
                        style: TextStyle(color: Colors.black, fontSize: 15),
                        textAlign: TextAlign.center,
                      ),
                      SvgPicture.asset(
                        'assets/mine/ic_btn_more.svg',
                        color: Colors.red,
                        width: 20,
                        height: 20,
                      ),
                    ],
                  ),
                  const SizedBox(height: 30),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '消息通知设置',
                        style: TextStyle(color: Colors.black, fontSize: 15),
                        textAlign: TextAlign.center,
                      ),
                      SvgPicture.asset(
                        'assets/mine/ic_btn_more.svg',
                        color: Colors.red,
                        width: 20,
                        height: 20,
                      ),
                    ],
                  ),
                  const SizedBox(height: 30),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '修改密码',
                        style: TextStyle(color: Colors.black, fontSize: 15),
                        textAlign: TextAlign.center,
                      ),
                      SvgPicture.asset(
                        'assets/mine/ic_btn_more.svg',
                        color: Colors.red,
                        width: 20,
                        height: 20,
                      ),
                    ],
                  ),
                  const SizedBox(height: 30),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '清理缓存',
                        style: TextStyle(color: Colors.black, fontSize: 15),
                        textAlign: TextAlign.center,
                      ),
                      SvgPicture.asset(
                        'assets/mine/ic_btn_more.svg',
                        color: Colors.red,
                        width: 20,
                        height: 20,
                      ),
                    ],
                  )
                ],
              )),
          const SizedBox(height: 30),
          Container(
            margin: const EdgeInsets.all(20),
            width: MediaQuery.of(context).size.width * 0.9,
            height: 50,
            child: ElevatedButton(
                style: ElevatedButton.styleFrom(
                  backgroundColor: const Color.fromARGB(255, 255, 255, 255),
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(10)),
                ),
                onPressed: () {
                  showDialogFunction(context);
                },
                child: const Text(
                  '退出登录',
                  style: TextStyle(color: Colors.black),
                )),
          )
        ]));
  }
}
